﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ProjectRepository.cs" company="">
//   Copyright (c) 2010/2011 All Right Reserved
// </copyright>
// <summary>
//   Contains ProjectRepository class declaration.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace iBuproModel.Repositories.Classes
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    using iBuproModel.Repositories.Interfaces;

    /// <summary>
    /// Implements IProjectRepository interface using linq to entities.
    /// </summary>
    public class ProjectRepository : GenericRepository<Project>, IProjectRepository
    {   
        public IEnumerable<Project> GetProjectsForSubject(int id)
        {
            return this.context.Projects.Where(p => p.Subject.Id == id).OfType<Project>().ToList();
        }

        public IEnumerable<Project> GetProjectsForUser(string username)
        {
            return this.context.Users.Where(u => u.Username == username).SingleOrDefault().Projects.ToList();
        }

        public IEnumerable<Project> GetProjectsForUser(User user)
        {
            return user.Projects.OfType<Project>().ToList();
        }

    }
}
